<template>
  <div>
    
    <el-button slot="reference" @click="addCourseTreatmentForm" type='primary' class="ml-1" >新增疗程计划</el-button>
    <el-button slot="reference" @click="openDrawer" type='primary' class="ml-1">所有治疗计划</el-button>

    <div class="mt-2">
      <treatmentTable :list="tableList" :providerId="providerId"  :pid="pid" :typeList="typeList" @successSubmit="successSubmit"></treatmentTable>
    </div>
      <!-- 所有治疗计划 -->
    <el-drawer :visible.sync="drawer.open" direction="rtl" size="70%" @opened="openedDrawer">
      <template v-slot:title>
        <div class="text-center">
          <el-select v-model="treatmentType" placeholder="请选择" class="width220" @change="changeTreatmentType">
            <el-option v-for="item in typeListForQuery" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
      </div>
      </template>
      <div class="px-2"><allPlan  ref="allPlanRef" :treatmentType="treatmentType"></allPlan></div> 
    </el-drawer>

    <el-dialog :title="dialog1.title" :visible.sync="dialog1.open" width="1000" top="70px" :close-on-click-modal="false" class="bodyNopaddingTop" @opened="openedDialog1">
      <courseTreatmentForm :providerId="providerId" @submitSuccess="submitSuccess1" :model="dialog1.model" :typeList="typeList" ref="courseTreatmentForm"/>
    </el-dialog>

  </div>
</template>
<script>
import {getPlanTreatmentList,treatmentTypeList,getCourseTreatmentList} from "plugins/axios/inquiryRecord.js"

// 治疗疗程计划form
import courseTreatmentForm from 'views/operationManage/components/inquiryRecordDetail/treatmentPlan/courseTreatmentForm.vue';
// 治疗计划列表
import treatmentTable from 'views/operationManage/components/inquiryRecordDetail/treatmentPlan/treatmentTable.vue';

// 所有治疗计划
import allPlan from 'views/operationManage/components/inquiryRecordDetail/allPlan.vue';
import {getCalendar}  from 'plugins/calendar.js'

export default {
  components:{
    courseTreatmentForm,
    treatmentTable,
    allPlan
  },
  props:{
    providerId:{
      type:[String,Number]
    },
    pid:{
      type:[String,Number]
    }
  },
  data(){
    return{
      visible:false,
      calendarObj:{},
      calendarList:[],
      tableList:[],
      typeList:[],
      typeListForQuery:[],

      courseTreatmentList:[],
      courseTreatment:null,
      drawer:{
        open:false
      },
      dialog:{
        title:'',
        open:false,
        model:{},
        type:'',
      },
      dialog1:{
        title:'',
        open:false,
        model:{}
      },
      treatmentType:''
    }
  },
  created(){
    let self = this;
    treatmentTypeList().then(res=>{
      self.typeList=res.content;
      self.typeListForQuery=self.typeList;
      self.typeListForQuery.unshift({id:0,name:'所以类型'});
      self.treatmentType=res.content[0].id
    })
  },
  mounted(){},
  watch:{},
  computed:{},
  methods:{
    init(date){
      this.calendarObj = getCalendar(date);
      this.getPlanTreatmentList();
      this.getCourseTreatmentList();
    },
    getCourseTreatmentList(){
      let self = this;
      getCourseTreatmentList(self.providerId).then(res=>{
        self.courseTreatmentList= res.content;
      })
    },
    getPlanTreatmentList(){
      let self= this,postData={
        providerNo:self.providerId,
        treatmentPeriod:self.courseTreatment
    }
    getPlanTreatmentList(postData).then(res=>{
      debugger;
        self.tableList=res.content;
      })
    },
    popoverCanle(){
      this.visible=false;
    },
    submitSuccess(){
      this.dialog.open = false;
      this.init(new Date());
      console.log("调用成功");
    },
   changeTime(date){
      this.init(date)
   },
  //  点击打开查看所有治疗计划
   openDrawer(){
     this.drawer.open=true;
     
   },
   openedDrawer(){
     this.$refs.allPlanRef.init(this.treatmentType);
   },
   openedDialog1(){
      this.$refs.courseTreatmentForm.init();
   },
   showDialog(type,item){
     this.dialog.title=`${type==='insert'?'新增':'修改'}计划`
     this.dialog.open = true;
     this.dialog.type=type
     this.dialog.model = type==='insert'?{}:{...item}
   },
   canle(){
     this.dialog.open = false;
   },
   //  点击关闭查看所有治疗计划
   handleClose(){

   },
   addCourseTreatmentForm(){
     this.dialog1.open=true;
     this.dialog1.title="新增疗程计划"
     this.dialog1.model={}
   },
   submitSuccess1(){
     this.dialog1.open=false;
     this.init()
   },
   successSubmit(){
       this.init(new Date());
   },
   changeTreatmentType(val){
     this.treatmentType=val;
     this.$refs.allPlanRef.init(this.treatmentType);
   }
  }
}
</script>
<style scoped>
</style>